# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=py3-spsdk
pkgver=1.10.0
pkgrel=3
pkgdesc="Open Source Secure Provisioning SDK for NXP MCU/MPU"
url="https://github.com/NXPmicro/spsdk"
# s390x, ppc64le and riscv64 blocked by py3-cmsis-pack-manager
arch="noarch !s390x !ppc64le !riscv64"
license="BSD-3-Clause"
depends="
	pcsc-lite-libs
	py3-asn1crypto
	py3-astunparse
	py3-bincopy
	py3-bitstring
	py3-click
	py3-click-command-tree
	py3-click-option-group
	py3-cmsis-pack-manager
	py3-colorama
	py3-commentjson
	py3-crcmod
	py3-cryptography
	py3-deepmerge
	py3-fastjsonschema
	py3-hexdump
	py3-jinja2
	py3-libusbsio
	py3-oscrypto
	py3-pycryptodome
	py3-pylink-square
	py3-pyocd
	py3-pyscard
	py3-pyserial
	py3-ruamel.yaml
	py3-sly
	py3-typing-extensions
	python3
	"
makedepends="
	py3-gpep517
	py3-installer
	py3-setuptools
	py3-wheel
	"
checkdepends="
	py3-attrs
	py3-pytest
	py3-voluptuous
	"
subpackages="$pkgname-pyc spsdk:_spsdk"
source="spsdk-$pkgver.tar.gz::https://github.com/NXPmicro/spsdk/archive/refs/tags/$pkgver.tar.gz
	0001-Remove-pypemicro.patch
	0002=-Fix-circular-import-error-in-signature-provider.patch::https://github.com/NXPMicro/spsdk/commit/bae3d35c008d9534710454232059f1fc2ed7ec84.patch
	"
builddir="$srcdir/spsdk-$pkgver"

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	.testenv/bin/python3 -m unittest discover \
		-k 'not test_keys_generation_ec and not test_key_types and not test_matching_keys_ecc'
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

_spsdk() {
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin
	amove usr/lib/python*/site-packages/spsdk/apps/*.py
}

sha512sums="
44d4056bceb01ff9454bc0b50af309006176f729c02bcfb3a6e61bd75720824cf97d54ef6bc2920e37a9bb1775b71c002a6e56b320362a4dd61e9bb9b12cfaa1  spsdk-1.10.0.tar.gz
a2bdbc319ad22c705ce6995892a11f6fadd534573dbe8219b942759ed3d193b7ce32a21e45ca59f2c3bfcb2fabeb6eb48163300454f7295dff1b08d0f7639527  0001-Remove-pypemicro.patch
1d7669680024ee196a944d6046469c0a50246daa314d3178616095cfb329c6b02acf4bb181145aeffc0bc7bf2c8ffc21d77a37f7e1fa219ad3b3da5930532e4e  0002=-Fix-circular-import-error-in-signature-provider.patch
"
